home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / Booting Gallery / Booting Gallery (source) / Sources / Sprite Sources / Sprite.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  3.6 KB  |  172 lines  |  [TEXT/BROW]

  1. #pragma once
  2. #include <QDOffscreen.h>
  3. #include <TObjectQueue.h>
  4. #include <retrace.h>
  5. #include "LockPixMap.h"
  6. #include "MHeapObject.h"
  7. #include "A5World.h"
  8.  
  9. class StSaveGWorld
  10. {
  11. public:
  12.     StSaveGWorld();
  13.     ~StSaveGWorld();
  14.     
  15.      
  16. protected:
  17.     GWorldPtr        fSaveGWorld;
  18.     GDHandle        fSaveGD;
  19. };
  20.  
  21. class CSprite;
  22. class CSpriteCanvas;
  23.  
  24. class CSpriteWorld
  25. {
  26.     friend    class CSprite;
  27. public:
  28.     CSpriteWorld(OSErr&    err);
  29.     ~CSpriteWorld();
  30.     
  31.     void            Start();
  32.     void            Stop();
  33.     
  34.     CSpriteCanvas*    GetSpriteCanvas()            {return fCanvas;}
  35.     CSpriteCanvas*    GetBackgroundCanvas()        {return fBackground;}
  36.     
  37.     TObjectQueue<CSprite>&    GetSpriteQueue()    {return fSpriteQueue;}
  38.     
  39.     void            Idle();    // DONT CALL THIS, this is public for debugging only
  40.  
  41. protected:    
  42.     void            AddSprite(CSprite* sprite);
  43.     void            RemoveSprite(CSprite* sprite);
  44.  
  45.     void            UpdateSpriteLocations();
  46.     void            DrawAll();
  47.     void            DrawBackground(); 
  48.     void            DrawSprites();
  49.     void            CheckForHits();
  50.     void            CheckForHitsOnThisSprite(CSprite*    thisOne);
  51.     
  52.     virtual void    ImageBackground(CSpriteCanvas* canvas);
  53.     
  54.     enum{    kInterval = 3};
  55.     struct ExtendedVBL : VBLTask
  56.     {
  57.         long            saveGlobals;
  58.         CSpriteWorld*    thisObj;
  59.     };
  60.     
  61.     static    void    _VBLTask();
  62.             void    InstallVBL();
  63.             void    RemoveVBL();
  64.     
  65.     TObjectQueue<CSprite>        fSpriteQueue;
  66.     CSpriteCanvas*                fBackground;
  67.     CSpriteCanvas*                fCanvas;
  68.     PixMapHandle                fMainPixMap;
  69.     char                        fDeviceState;
  70.     PixMapState                    fMainPixMapState;
  71.     Boolean                        fVBLInstalledQ;
  72.     ExtendedVBL                    fVBL;
  73.     A5World                        fA5World;
  74.  
  75. };
  76.  
  77.  
  78. class CSpriteCanvas
  79. {
  80. public:
  81.     CSpriteCanvas(OSErr& err);
  82.     ~CSpriteCanvas();
  83.      
  84.     const     Rect*        GetBounds()            {return &fBounds;}
  85.             void        Blit(PixMapHandle pm,
  86.                             const Rect& inSourceRect,
  87.                             const Rect& inDestRect,
  88.                             RgnHandle inSourceMask);
  89.                             
  90.             PixMapHandle    GetPixMap()        {return fPixMap;}
  91.             GWorldPtr        GetGWorld()        {return fGWorld;}
  92.             
  93.             void        PrepareToDraw();
  94. protected:
  95.     GWorldPtr        fGWorld;
  96.     PixMapHandle    fPixMap;
  97.     Rect            fBounds;
  98. };
  99.  
  100.  
  101. class CSprite : public     TQueueElem<CSprite> , 
  102.                 public    MHeapObject
  103. {
  104. public:
  105.                     CSprite(CSpriteWorld* theWorld,long id,const Rect& inStart);
  106.     virtual         ~CSprite();
  107.     
  108.     
  109.     virtual    void    UpdatePosition() = 0;
  110.     virtual void    Draw() = 0;
  111.     virtual    Boolean    WasHitBy(CSprite* hitByThis) {return true;};
  112.     
  113.             long            GetID()                {return fID;}
  114.             Rect*            GetLocation()        {return &fLocation;}
  115.             short            Width()                {return fLocation.right - fLocation.left;}
  116.             short            Height()            {return fLocation.bottom - fLocation.top;}
  117.             
  118.             void            MoveBy(short dX,short dY)    {OffsetRect(&fLocation,dX,dY);}
  119.             void            MoveTo(short x,short y)        {OffsetRect(&fLocation,
  120.                                                                 x - fLocation.left,
  121.                                                                 y - fLocation.top); }
  122.             Boolean            OutOfBoundsQ();
  123.             void            MoveToH(short h)            {OffsetRect(&fLocation,h - fLocation.left,0);}
  124.             void            MoveToV(short v)            {OffsetRect(&fLocation,0,v - fLocation.top);}
  125.             
  126.             CSpriteWorld*    GetWorld()    {return fWorld;}
  127.     const    Rect*            GetGameBounds();
  128.     
  129. protected:
  130.  
  131.             Boolean            KeyIsDownQ(short keyCode);
  132.  
  133.  
  134.     long            fID;
  135.     Rect            fLocation;
  136.     CSpriteWorld*    fWorld;
  137.     
  138. private:
  139.  
  140. };
  141.  
  142.  
  143. class CPixMapSprite : public CSprite
  144. {
  145. public:
  146.                     CPixMapSprite(CSpriteWorld* world,long id,GWorldPtr image,
  147.                         short startTop,short startLeft,RgnHandle mask);
  148.     virtual            ~CPixMapSprite();
  149.                 
  150.             void    SetImage(GWorldPtr    image,RgnHandle mask);
  151.     virtual void    Draw();
  152.     
  153. protected:
  154.     PixMapHandle    fPixMap;
  155.     GWorldPtr        fGWorld;
  156.     RgnHandle        fSourceMask;
  157. };
  158.  
  159. class CHPixMapSprite : public CPixMapSprite
  160. {
  161. public:
  162.             CHPixMapSprite(CSpriteWorld* world,long id,GWorldPtr image,
  163.                         short startTop,short startLeft,RgnHandle mask);
  164.                         
  165.     virtual    ~CHPixMapSprite();
  166.                         
  167.     virtual void    UpdatePosition();
  168.  
  169. };
  170.  
  171.  
  172.